package bfw3b9.atprin.project;

import java.util.ArrayList;

import android.graphics.Color;
import android.view.Gravity;
import android.widget.Button;
import android.widget.RelativeLayout;
import android.widget.TextView;


/**
 * @author Tobias Sommer
 * 
 * Haelt Funktionen die die UI aufbauen und die Daten fuer das Level und die Creeps liefern.
 * Der gesamte Inhalt ist static.
 */
public class LevelConstructor {
	
	//IDs der UI Elemente
	public static final int WAVE_BUTTON = 1;
	public static final int LEVEL_TEXT = 2;
	public static final int LEVEL_VALUE = 3;
	public static final int WAVE_TEXT = 4;
	public static final int WAVE_VALUE = 5;
	public static final int LIFE_TEXT = 6;
	public static final int LIFE_VALUE = 7;
	
	
	/**
	 * @author Tobias Sommer
	 * 
	 * Erstellt den Pfad
	 * 
	 * @param _width, Breite des Spielfelds
	 * @param _height, Hoehe des Spielfelds
	 * @return der gesamte Pfad
	 */
	public static ArrayList<DirectionPoint> createLevel1Path(int _width, int _height){
		
		ArrayList<DirectionPoint> arlPath = new ArrayList<DirectionPoint>();
		float xgrid = _width / 20;
		float ygrid = _height / 12; 
		float x = 0;
		float y = ygrid * 3 + ygrid / 2;
		float direction = DirectionPoint.EAST;
		
		while(x<=xgrid * 5 + xgrid / 2){
			arlPath.add(new DirectionPoint(x,y,direction));
			x++;
		}
		direction = DirectionPoint.SOUTH;
		while(y<= ygrid * 8 + ygrid / 2){
			arlPath.add(new DirectionPoint(x,y,direction));
			y++;
		}
		direction = DirectionPoint.EAST;
		while(x<=xgrid * 9 + xgrid / 2){
			arlPath.add(new DirectionPoint(x,y,direction));
			x++;
		}
		direction = DirectionPoint.NORTH;
		while(y>=ygrid * 3 + ygrid / 2){
			arlPath.add(new DirectionPoint(x,y,direction));
			y--;
		}
		direction = DirectionPoint.EAST;
		while(x<=xgrid * 16 + xgrid / 2){
			arlPath.add(new DirectionPoint(x,y,direction));
			x++;
		}
		direction = DirectionPoint.SOUTH;
		while(y<=ygrid * 6 + ygrid / 2){
			arlPath.add(new DirectionPoint(x,y,direction));
			y++;
		}
		direction = DirectionPoint.EAST;
		while(x<=_width){
			arlPath.add(new DirectionPoint(x,y,direction));
			x++;
		}
		
		return arlPath;
	}
	
	/**
	 * @author Tobias Sommer
	 * 
	 * Erstellt alle Waves mit ihren Creeps fuer das 1. Level.
	 * 
	 * @return Liste mit den Waves, die jeweils ihre Creeps halten
	 */
	public static ArrayList<ArrayList<Creep>> createLevel1Creeps(){
		
		ArrayList<ArrayList<Creep>> arlCreeps = new ArrayList<ArrayList<Creep>>();
		
		arlCreeps.add(new ArrayList<Creep>());
		arlCreeps.get(0).add(new Creep(100, 5, R.drawable.creep));
		arlCreeps.get(0).add(new Creep(100, 5, R.drawable.creep));
		arlCreeps.get(0).add(new Creep(100, 5, R.drawable.creep));
		arlCreeps.get(0).add(new Creep(100, 5, R.drawable.creep));
		arlCreeps.get(0).add(new Creep(100, 5, R.drawable.creep));
		arlCreeps.get(0).add(new Creep(100, 5, R.drawable.creep));
		arlCreeps.get(0).add(new Creep(100, 5, R.drawable.creep));
		arlCreeps.get(0).add(new Creep(100, 5, R.drawable.creep));
		arlCreeps.get(0).add(new Creep(100, 5, R.drawable.creep));
		arlCreeps.get(0).add(new Creep(200, 10, R.drawable.creep));
		
		arlCreeps.add(new ArrayList<Creep>());
		arlCreeps.get(1).add(new Creep(100, 5, R.drawable.creep));
		arlCreeps.get(1).add(new Creep(100, 5, R.drawable.creep));
		arlCreeps.get(1).add(new Creep(100, 5, R.drawable.creep));
		arlCreeps.get(1).add(new Creep(100, 5, R.drawable.creep));
		arlCreeps.get(1).add(new Creep(100, 5, R.drawable.creep));
		arlCreeps.get(1).add(new Creep(100, 5, R.drawable.creep));
		arlCreeps.get(1).add(new Creep(100, 5, R.drawable.creep));
		arlCreeps.get(1).add(new Creep(100, 5, R.drawable.creep));
		arlCreeps.get(1).add(new Creep(100, 5, R.drawable.creep));
		arlCreeps.get(1).add(new Creep(200, 10, R.drawable.creep));
		
		arlCreeps.add(new ArrayList<Creep>());
		arlCreeps.get(2).add(new Creep(100, 5, R.drawable.creep));
		arlCreeps.get(2).add(new Creep(100, 5, R.drawable.creep));
		arlCreeps.get(2).add(new Creep(100, 5, R.drawable.creep));
		arlCreeps.get(2).add(new Creep(100, 5, R.drawable.creep));
		arlCreeps.get(2).add(new Creep(100, 5, R.drawable.creep));
		arlCreeps.get(2).add(new Creep(100, 5, R.drawable.creep));
		arlCreeps.get(2).add(new Creep(100, 5, R.drawable.creep));
		arlCreeps.get(2).add(new Creep(100, 5, R.drawable.creep));
		arlCreeps.get(2).add(new Creep(100, 5, R.drawable.creep));
		arlCreeps.get(2).add(new Creep(200, 10, R.drawable.creep));
		
		return arlCreeps;
	}
	
	/**
	 * @author Tobias Sommer
	 * 
	 * Erzeugt die Karte.
	 * 
	 * @return Karte
	 */
	public static int[][] createMap(){
		int [][] map = {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
						{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
						{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
						{-1,-1,-1,-1,-1,-1, 0, 0, 0,-1,-1,-1,-1,-1,-1,-1,-1, 0, 0, 0},
						{ 0, 0, 0, 0, 0,-1, 0, 0, 0,-1, 0, 0, 0, 0, 0, 0,-1, 0, 0, 0},
						{ 0, 0, 0, 0, 0,-1, 0, 0, 0,-1, 0, 0, 0, 0, 0, 0,-1, 0, 0, 0},
						{ 0, 0, 0, 0, 0,-1, 0, 0, 0,-1, 0, 0, 0, 0, 0, 0,-1,-1,-1,-1},
						{ 0, 0, 0, 0, 0,-1, 0, 0, 0,-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
						{ 0, 0, 0, 0, 0,-1,-1,-1,-1,-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
						{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
						{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
						{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}};
		return map;
	}
	
	
	/**
	 * @author Tobias Sommer
	 * 
	 * Erzeugt die UI Elemente und platziert sie in dem Layout der Activity
	 * 
	 * @param _con, Activity
	 * @param _rlay, Layout der Activity
	 * @return veraenderte Layout
	 */
	public static RelativeLayout createLayout(GameController _con, RelativeLayout _rlay){
		Button btn = _con.waveBtn;
		new WaveButtonListener(btn);
		TextView lbl;
		
		//Button
		btn.setText("Next Wave");
		btn.setWidth((int)(_rlay.getWidth()*0.20));
		btn.setId(LevelConstructor.WAVE_BUTTON);
		RelativeLayout.LayoutParams x = new RelativeLayout.LayoutParams(120, 80);
		x.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
		x.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
		_rlay.addView(btn, x);
		
		//Label fuer das Leben
		lbl = new TextView(_con);
		lbl.setText("Life:");
		lbl.setWidth((int)(_rlay.getWidth()*0.15));
		lbl.setId(LevelConstructor.LIFE_TEXT);
		lbl.setBackgroundColor(Color.GRAY);
		lbl.setTextSize(20);
		lbl.setGravity(Gravity.CENTER);
		x = new RelativeLayout.LayoutParams(100, 40);
		x.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
		x.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
		_rlay.addView(lbl, x);
		
		//Label fuer die Waves
		lbl = new TextView(_con);
		lbl.setText("Wave:");
		lbl.setWidth((int)(_rlay.getWidth()*0.15));
		lbl.setId(LevelConstructor.WAVE_TEXT);
		lbl.setBackgroundColor(Color.GRAY);
		lbl.setTextSize(20);
		lbl.setGravity(Gravity.CENTER);
		x = new RelativeLayout.LayoutParams(100, 40);
		x.addRule(RelativeLayout.ABOVE,LevelConstructor.LIFE_TEXT);
		x.addRule(RelativeLayout.ALIGN_LEFT,LevelConstructor.LIFE_TEXT);
		_rlay.addView(lbl, x);
		
		//Label fuer das Level
		lbl = new TextView(_con);
		lbl.setText("Level:");
		lbl.setWidth((int)(_rlay.getWidth()*0.20));
		lbl.setId(LevelConstructor.LEVEL_TEXT);
		lbl.setBackgroundColor(Color.GRAY);
		lbl.setTextSize(20);
		lbl.setGravity(Gravity.CENTER);
		x = new RelativeLayout.LayoutParams(100, 40);
		x.addRule(RelativeLayout.ABOVE,LevelConstructor.WAVE_TEXT);
		x.addRule(RelativeLayout.ALIGN_LEFT,LevelConstructor.LIFE_TEXT);
		_rlay.addView(lbl, x);
		
		//Lebenswert
		lbl = _con.labelLife;
		lbl.setText("10");
		lbl.setWidth((int)(_rlay.getWidth()*0.10));
		lbl.setId(LevelConstructor.LIFE_VALUE);
		lbl.setBackgroundColor(Color.GRAY);
		lbl.setTextSize(20);
		lbl.setGravity(Gravity.CENTER);
		x = new RelativeLayout.LayoutParams(60, 40);
		x.addRule(RelativeLayout.RIGHT_OF,LevelConstructor.LIFE_TEXT);
		x.addRule(RelativeLayout.ALIGN_BOTTOM,LevelConstructor.LIFE_TEXT);
		_rlay.addView(lbl, x);
		
		//Wavenummer
		lbl = _con.labelWave;
		lbl.setText("1");
		lbl.setWidth((int)(_rlay.getWidth()*0.10));
		lbl.setId(LevelConstructor.WAVE_VALUE);
		lbl.setBackgroundColor(Color.GRAY);
		lbl.setTextSize(20);
		lbl.setGravity(Gravity.CENTER);
		x = new RelativeLayout.LayoutParams(60, 40);
		x.addRule(RelativeLayout.ABOVE,LevelConstructor.LIFE_VALUE);
		x.addRule(RelativeLayout.ALIGN_LEFT,LevelConstructor.LIFE_VALUE);
		_rlay.addView(lbl, x);
		
		//Levelnummer
		lbl = _con.labelLevel;
		lbl.setText("1");
		lbl.setWidth((int)(_rlay.getWidth()*0.10));
		lbl.setId(LevelConstructor.LEVEL_VALUE);
		lbl.setBackgroundColor(Color.GRAY);
		lbl.setTextSize(20);
		lbl.setGravity(Gravity.CENTER);
		x = new RelativeLayout.LayoutParams(60, 40);
		x.addRule(RelativeLayout.ABOVE,LevelConstructor.WAVE_VALUE);
		x.addRule(RelativeLayout.ALIGN_LEFT,LevelConstructor.LIFE_VALUE);
		_rlay.addView(lbl, x);
		
		
		return _rlay;
	}

}
